﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Benlai.Model.Doc;
using Benlai.Dac.Mongo;
using MongoDB.Driver;

namespace Benlai.Dac.Doc
{
    public class TableDac : MongoHandler<TableModel>
    {
        public TableDac()
        {
            DBName = "houtai";
            Name = "test";
            SortPropertyName = "ColumnName";
            IsDescending = false;
        }

        public TableModel Get(string id)
        {
            return FindByID(id);
        }

        public List<TableModel> Get(string tableName, string columnName)
        {
            return GetModel(new { ColumnName = columnName, TableName = tableName }).ToList<TableModel>();
        }

        public List<TableModel> GetByTableName(string tableName)
        {
            return GetModel(new { TableName = tableName }).ToList<TableModel>();
        }

        public List<TableModel> GetByColumnName(string columnName)
        {
            return GetModel(new { ColumnName = columnName }, "TableName", true).ToList<TableModel>();
        }

        public void Set(TableModel model)
        {
            if (string.IsNullOrEmpty(model.Id))
            {
                Insert(model);
            }
            else
            {
                Update(model, model.Id);
            }
        }


        public List<TableModel> GetList(int pageIndex, int pageSize, out int recordCount)
        {
            return GetModel(pageIndex, pageSize, out recordCount).ToList<TableModel>();
        }
    }
}
